#include('header.html')
<script type="text/javascript">
    changeTab('管理员信息');

    function gotoPage(e, page) {
        var name  = $('input[name="name"]').val();
        var pages = ${pages.totalPages};
        var status = $(e).parent().attr("class");
        if (page > 0 && page <= pages && page !== ${pages.number + 1} &&
            status !== "active") {
            location.href = '/admin/list?pageNo=' + page + "&name=" + name;
        }
    }

    function adminDelete(id, ad_name) {
        var flag = confirm('确定要删除<' + ad_name + '>吗？');
        if (flag) {
            $.post("/admin/delete/" + id, function (data) {
                if (data.status) {
                    alert("SUCCESS: 删除成功！");
                    location.reload();
                } else {
                    alert("ERROR: " + data.msg);
                    location.reload();
                }
            });
        }
    }

    function load_change(id) {
        var $modal = $("#shopModal");
        $modal.find(".modal-content").load("/admin/change/" + id);
        $modal.modal();
    }

    function load_add() {
        var $modal = $("#shopModal");
        $modal.find(".modal-content").load("/admin/add");
        $modal.modal();
    }
</script>

<!-- 动态加载的管理员添加 修改模态框 -->
<div class="modal fade" id="shopModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 模态框内容动态加载 -->
        </div>
    </div>
</div>

<div class="admin-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <a class="text-black" href="/admin/list">
                <h4><span class="fa fa-hand-o-right"></span> 管理员信息</h4>
            </a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <button onclick="load_add();" class="btn btn-warning btn-sm">添加</button>
                <form class="search pull-right" method="get">
                    <div class="input-group min-input">
                        <input name="name" style="height: 30px;" class="form-control" value="${name ?! ''}" type="text" placeholder="称谓">
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-default btn-sm">
                                <span class="fa fa-search"></span>
                            </button>
                        </span>
                    </div>
                </form>
            </div>
        </div>
        <div>
            <div class="col-lg-12 col-xs-12">
                <table class="table table-striped">
                    <thead class="bg-color-x">
                    <tr>
                        <td>索引</td>
                        <td>账号</td>
                        <td>称谓</td>
                        <td>电话</td>
                        <td>最后登录</td>
                        <td style="width: 120px;">操作</td>
                    </tr>
                    </thead>
                    <tbody>
                    #for(Admin a : pages.content)
                    <tr>
                        <td>${for.index}</td>
                        <td>${a.username}</td>
                        <td>${a.name}</td>
                        <td>${a.tel}</td>
                        <td>${a.loginTime.format('yyyy-MM-dd HH:mm') ?! '未使用'}</td>
                        <td>
                            #--只有普通管理员才可被操作--#
                            #if(a.grade <= 1)
                            <button onclick="load_change('${a.id}');"
                                    class="btn btn-xs btn-info">修改</button>
                            <button onclick="adminDelete('${a.id}', '${a.name}')"
                                    class="btn btn-xs btn-danger">删除</button>
                            #end
                        </td>
                    </tr>
                    #else
                    <tr>
                        <td align="center" colspan="6">
                            暂无数据  <a class="red-a" href="javascript:">快去添加</a>
                        </td>
                    </tr>
                    #end
                    </tbody>
                </table>
                <!-- 分页按钮 -->
                #if(pages.totalPages > 1)
                <div class="col-lg-12 col-xs-12 text-center">
                    <ul style="margin: 0;" class="pagination pagination-sm">
                       <!-- <li onclick="gotoPage(this, 1)"><a href="javascript:">首页</a></li>
                        #for(int i : range(1, pages.totalPages))
                        <li class="${i == pages.number + 1 ? 'active':''}"
                            onclick="gotoPage(this, ${i})"><a href="javascript:">${i}</a></li>
                        #end
                        <li onclick="gotoPage(this, ${pages.totalPages})"><a href="javascript:">尾页</a></li>-->
                    </ul>
                    <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
                            共${pages.totalPages}页，${pages.totalElements}条数据
                        </span>
                </div>
                #end
            </div>
        </div>
    </div>
</div>
#include('footer.html')